Imports N = NHibernate.Search
Public Class Form2

    Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Dim list As Generic.IList(Of Test)
        list = Search(txtSearch.Text)
        ListView1.Items.Clear()
        For Each t As Test In list
            ListView1.Items.Add(t.Body)
        Next
    End Sub

    Dim cfg As New NHibernate.Cfg.Configuration()
    Dim factory As NHibernate.ISessionFactory
    Dim nSession As NHibernate.ISession
    Dim session As NHibernate.Search.IFullTextSession
    Private Function Search(ByVal terms As String) As Generic.IList(Of Test)


        Dim parser As New Lucene.Net.QueryParsers.MultiFieldQueryParser(New String() {"Body", "Title"}, New Lucene.Net.Analysis.Standard.StandardAnalyzer())
        'Dim parser As New Lucene.Net.QueryParsers.QueryParser("Body", New )

        Dim query As Lucene.Net.Search.Query = parser.Parse(txtSearch.Text)
        Dim result As IList(Of Test)
        Dim q As NHibernate.IQuery

        'Dim SearchFactory As NHibernate.Search.Engine.SearchFactory = NHibernate.Search.Engine.SearchFactory.GetSearchFactory(cfg)
        'For Each obj As Test In result
        '    SearchFactory.PerformWork(obj, obj.MyID, session.GetSessionImplementation(), N.Backend.WorkType.Add)
        'Next

        q = session.CreateFullTextQuery(query, GetType(Test))
        result = q.List(Of Test)()
        Return result
    End Function

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cfg = cfg.Configure()
        factory = cfg.BuildSessionFactory()
        nSession = factory.OpenSession()
        session = NHibernate.Search.Search.CreateFullTextSession(nSession)
    End Sub
End Class